package com.esteel.settlement.dao.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.StringUtils;

import com.esteel.settlement.dao.ISettFundChgRepository;
import com.esteel.settlement.entity.TbSettFundChg;
import com.esteel.settlement.vo.FunChgQueryVo;

/**
 * 处理交易记录查询的类
 * @author zhangxiuzhi
 *
 */
public class SettFundChgRepositoryImpl implements ISettFundChgRepository{

	@Autowired
	private PageQuery pageQuery;
	
	@Override
	public Page<TbSettFundChg> findByCustAcctId(FunChgQueryVo vo) {
		StringBuilder sb = new StringBuilder("select t.* from tb_sett_fund_chg t where 1=1 ");
		List<Object> args = new ArrayList<Object>();
		if (!StringUtils.isEmpty(vo.getCustAcctId())){
			sb.append(" and t.cust_acct_id=?");
			args.add(vo.getCustAcctId());
		}
		if (vo.getBegin()!=null){
			sb.append(" and t.trans_date >?");
			args.add(vo.getBegin());
		}
		if (vo.getEnd()!=null){
			sb.append(" and t.trans_date <?");
			Date end = vo.getEnd();
			Calendar cal = Calendar.getInstance();
			cal.setTime(end);
			cal.add(Calendar.DATE, 1);
			args.add(cal.getTime());
		}
		
		sb.append(" order by chg_id desc");
		
		return pageQuery.query(sb.toString(), args.toArray(), vo, TbSettFundChg.class);
	}

}
